//
//  LeftMenuTableHeader.m
//  囧途
//
//  Created by 杨璟 on 16/3/10.
//  Copyright © 2016年 fly. All rights reserved.
//

#import <AVUser.h>
#import "LeftMenuTableHeader.h"
#import "UIView+Extension.h"
#import "JTUser.h"
#import "UIImageView+WebCache.h"

@interface LeftMenuTableHeader ()

@property (weak, nonatomic) IBOutlet UIImageView *userIcon;

@property (weak, nonatomic) IBOutlet UILabel *userName;


@end

@implementation LeftMenuTableHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    
    UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconPressed)];
    [self.userIcon addGestureRecognizer:iconTap];
    
    self.userIcon.layer.cornerRadius = 50;
    self.userIcon.layer.borderWidth = 1;
    self.userIcon.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    self.userIcon.layer.masksToBounds = YES;
    
    self.height = 250;
}

+ (instancetype)headerWithUser:(JTUser *)user {
    LeftMenuTableHeader *header = [[[NSBundle mainBundle] loadNibNamed:@"LeftMenuTableHeader" owner:self options:nil] lastObject];
    
    header.currentUser = user;
    
    return header;
}

- (void)setCurrentUser:(JTUser *)currentUser {
    _currentUser = currentUser;
    
    [self.userIcon sd_setImageWithURL:currentUser.iconPath placeholderImage:[UIImage imageNamed:@"头像占位"]];
    if (currentUser.nickname) {
        self.userName.text = currentUser.nickname;
    } else {
        self.userName.text = @"点击头像登录";
    }
}

- (void)iconPressed {
    NSLog(@"Tap");
    if ([self.delegate respondsToSelector:@selector(didClickIcon:)]) {
        [self.delegate didClickIcon:self];
    }
}

@end
